import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import viteSvgIcons from "vite-plugin-svg-icons";
import { resolve } from "path";

function pathResolve(dir: string) {
	return resolve(process.cwd(), ".", dir);
}

// https://vitejs.dev/config/

export default defineConfig({
	plugins: [
		vue(),
		// 加载 svg
		viteSvgIcons({
			// 指定需要缓存的图标文件夹
			iconDirs: [pathResolve("src/icons/svg")],
			// 指定symbolId格式
			symbolId: "icon-[dir]-[name]",
		}),
	],
	root: process.cwd(),
	base: "./",
	resolve: {
		alias: [
			{ find: "@", replacement: pathResolve("/src") },
			{ find: "@img", replacement: pathResolve("/src/assets/images") },
			{ find: "@ts", replacement: pathResolve("/src/assets/ts") },
			//解决开发环境下的警告 You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.
			{ find: "vue-i18n", replacement: "vue-i18n/dist/vue-i18n.cjs.js" },
		],
		// 导入时想要省略的扩展名列表。注意，不 建议忽略自定义导入类型的扩展名（例如：.vue），因为它会影响 IDE 和类型支持。
		extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"],
	},
	css: {
		preprocessorOptions: {
			scss: {
				additionalData: `@import "@/style/config.scss";@import "@/style/variables.scss";`,
			},
		},
	},
	json: {
		// 是否支持从 .json 文件中进行按名导入。
		namedExports: true,
		// 若设置为 true，导入的 JSON 会被转换为 export default JSON.parse("...")，这样会比转译成对象字面量性能更好，尤其是当 JSON 文件较大的时候。
		// 开启此项，则会禁用按名导入。
		stringify: false,
	},
	server: {
		host: "0.0.0.0",
		port: 9527,
		proxy: {},
	},
	define: {
		// __VUE_I18N_LEGACY_API__: false,
		// __VUE_I18N_FULL_INSTALL__: false,
		__INTLIFY_PROD_DEVTOOLS__: false,
	},
	build: {
		outDir: "dist",
		assetsDir: "assets",
		minify: "esbuild",
		assetsInlineLimit: 4096,
		rollupOptions: {
			// external: [
			// 	"naive-ui",
			// 	"@vicons/antd",
			// 	"@vicons/carbon",
			// 	"@vicons/fa",
			// 	"@vicons/fluent",
			// 	"@vicons/ionicons4",
			// 	"@vicons/ionicons5",
			// 	"@vicons/material",
			// 	"@vicons/tabler",
			// ],
		},
	},
});
